package com.finupgroup.postloan.generator.config;

import com.finupgroup.postloan.generator.PropUtils;

/**
 * 跟包相关的配置项
 *
 * @author YueQingwei
 * @since 2018-04-10
 */
public class PackageInfo {

    /**
     * 项目名
     */
    private String project;

    /**
     * 模块名，自动截取project后缀，用作project的包路径
     */
    private String[] modules;

    /**
     * 父包名。如果为空，将下面子包名必须写全部， 否则就只需写子包名
     */
    private String parent;

    /**
     * Entity包名
     */
    private String entity;

    /**
     * Service包名
     */
    private String service;

    /**
     * Service Impl包名
     */
    private String serviceImpl;
    /**
     * Mapper包名
     */
    private String mapper;

    /**
     * Mapper XML包名
     */
    private String xml;

    /**
     * Controller包名
     */
    private String controller;

    public PackageInfo() {
        project = PropUtils.get("project.name");
        modules = project.split("-");
        parent = "com.finupgroup.postloan";
        entity = joinPackage("model");
        mapper = joinPackage("mapper");
        xml = "mappers";
        service = joinPackage("service");
        serviceImpl = joinPackage("service.impl");
        controller = joinPackage("rest");
    }

    private String joinPackage(String subPackage) {
        return this.parent + "." + this.modules[0] + "." + this.modules[1] + "." + subPackage;
    }

    public String getProject() {
        return project;
    }

    public String getParent() {
        return parent;
    }

    public String getEntity() {
        return entity;
    }

    public String getEntityProject() {
        return project + "-model";
    }

    public String getService() {
        return service;
    }

    public String getServiceImpl() {
        return serviceImpl;
    }

    public String getServiceProject() {
        return project + "-service";
    }

    public String getMapper() {
        return mapper;
    }

    public String getXml() {
        return xml;
    }

    public String getMapperProject() {
        return project + "-mapper";
    }

    public String getController() {
        return controller;
    }

    public String getControllerProject() {
        return project + "-rest";
    }
}
